<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .login-box {
            position: fixed;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            width: 450px;
            height: 150px;
            box-sizing: border-box;
            padding: 10px;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 0 4px rgba(0, 0, 0, 0.297);
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: space-between;
        }

        .logo {
            width: 64px;
            height: 64px;
            margin: 0 20px;
            user-select: none;
        }

        .content {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 20px;
        }

        .input {
            width: calc(100% - 40px);
            border: 2px solid #83858d;
            padding: 5px;
            display: block;
            font-size: 16px;
            border-radius: 8px;
            transition: .3s;
            outline: none;
        }

        .input:focus {
            border: 2px solid #5c6bc0;
        }

        .auto-login {
            width: 140px;
            background-color: #5c6bc0;
            color: white;
            border: none;
            border-radius: 8px;
            padding: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: .3s;
        }

        .auto-login:hover {
            background-color: #697ad9;
        }

        .auto-login:active {
            background-color: #5c6bc0;
        }
    </style>
</head>

<body>
    <div class="login-box">
        <img class="logo" src="/favicon.ico" />
        <div class="content">
            <input class="input" type="password" placeholder="密钥" />
            <button class="auto-login" onclick="login()">授权</button>
        </div>
    </div>
    <script>
        async function login () {
            const input = document.querySelector('input')
            const secretKey = input.value

            const result = await fetch('/login', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    secretKey
                })
            }).then(res => res.json())
            if (result.result === 1) {
                // alert('授权成功')
                localStorage.setItem('secretKey', secretKey)
                window.location.href = '/'
            } else {
                alert(result.msg)
            }
        }
    </script>
</body>

</html>